home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / telecomm / uemlsrc.arc / kermit.c < prev    next >
C/C++ Source or Header  |  1987-08-24  |  21KB  |  608 lines

  1. /* kermit.c  support routines and main entry point for Uemail file transfer
  2.  * functions.  Kermit send, receive, get, put, finish, and bye supported.
  3.  * Buffer logging and direct ASCII transfer also available.  All actions are
  4.  * ASCII 7 bit files.  Transfers are made into and out of Uemail buffers.
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <osbind.h>
  9. #include <ctype.h>
  10. #include "ed.h"
  11. #include "kermit.h"
  12.  
  13.  
  14. int emacsfile;          /* if TRUE then \r become \n on ASCII transfers */
  15. char getfiln[NFILEN];   /* name for remote file get or put */
  16. char deflow[] = "XON/XOFF";
  17. static unsigned char *tsr_ptr = (char *)0x00fffa2d; /* See St internals */
  18. static long *hz_200 =  (long *)0x000004ba;
  19. int *aaddress(); /* thanks Jwahar R. Bammi for this line A code */
  20. int *aline_addr; /* Ptr to base of Aline variables */
  21. int sav_row, sav_col;
  22. int flow = DEFLO;       /* default flow control */
  23. int defbaud = 7;
  24. int bps = DEFBPS;
  25. unsigned long *hpterm;  /* HOST */
  26.  
  27. /* KERMIT CTRL command prompt for action and switch to appropriate state.
  28.  * Returns TRUE on success. !TRUE on failures.  Bound to ^_ and HELP on ST.
  29.  */
  30. kermit(flg, _n)
  31. register int flg, _n;
  32. {
  33.         static char command[9]; /* command */
  34.         register char key;
  35.         register int owf;
  36.  
  37.         owf = curwp->w_flag;            /* save for redraw */
  38.  
  39.         if ((_n=mlreply("Kermit-ST> ",command,8)) != TRUE)
  40.                 return(_n==FALSE ? FALSE : ABORT);
  41.  
  42.         /* Initialize these values */
  43.         /* Hope the first packet will get across OK */
  44.  
  45.         eol = CR;               /* EOL for outgoing packets */
  46.         quotech = '#';          /* Standard control-quote char "#" */
  47.         pad = 0;                /* No padding */
  48.         padchar = '\0';         /* Use null if any padding wanted */
  49.         timint = DEFTIME;       /* Default timeout */
  50.         parity = DEFPAR;        /* Default to no parity */
  51.         logfile = 0;            /* Capture flag */
  52.         emacsfile = 0;          /* Trans to emacs (no EOF) */
  53.         en8quote(FALSE);
  54.  
  55.         key = tolower(command[0]);
  56.         switch (key)
  57.                 {
  58.                 case 'b':               /* B = Bye */
  59.                         if(mlyesno("Logout remote")==TRUE)
  60.                                 if(gencmdsw('L')==FALSE)
  61.                                         {
  62.                                         mlwrite("Remote does not ACK BYE");
  63.                                         (*term.t_beep)();
  64.                                         return(FALSE);
  65.                                         }
  66.                         return(TRUE);   /* No update */
  67.                 case 'c':              /* C = Connect command */
  68.                         connect();
  69.                         break;
  70.                 case 'e':              /* E = transmit to GNU_EMACS command */
  71.                         if(usebuffer(NULL,NULL) != TRUE)
  72.                                 return(FALSE);
  73.                         gotobob(NULL, 1);
  74.                         update();
  75.                         mlwrite("[Transmitting %s to remote EMACS]",curbp->b_bna
  76. me);
  77.                         emacsfile = 1;
  78.                         trans();
  79.                         emacsfile = 0;
  80.                         connect();
  81.                         break;
  82.                 case 'f':               /* F = Finish */
  83.                         if(gencmdsw('F')==FALSE)
  84.                                 {
  85.                                 mlwrite("Remote does not ACK FINISH");
  86.                                 (*term.t_beep)();
  87.                                 return(FALSE);
  88.                                 }
  89.                         return(TRUE);   /* No update */
  90.                 case 'g':              /* G = Get command */
  91.                         if((_n=mlreply("Remote filename: ",getfiln,NFILEN))!=TRU
  92. E)
  93.                                 return(_n);
  94.                         if(usebuffer(NULL,NULL) != TRUE)
  95.                                 return(FALSE);
  96.                         gotoeob(NULL, 1);
  97.                         update();
  98.                         if((_n=getsw()) == FALSE)
  99.                                 {
  100.                                 (*term.t_beep)();
  101.                                 mlreply("Get failed. Type <CR>",command,2);
  102.                                 }
  103.                         break;
  104.                 case 'l':       /* L = Log session */
  105.                         if(usebuffer(NULL,NULL) != TRUE)
  106.                                 return(FALSE);
  107.                         gotoeob(NULL, 1);
  108.                         logfile = TRUE;
  109.                         connect();
  110.                         break;
  111.                 case 'r':              /* R = Receive command */
  112.                         if(usebuffer(NULL,NULL) != TRUE)
  113.                                 return(FALSE);
  114.                         gotoeob(NULL, 1);
  115.                         update();
  116.                         if((_n=recsw()) == FALSE)
  117.                                 {
  118.                                 (*term.t_beep)();
  119.                                 mlreply("Receive failed. Type <CR>",command,2);
  120.                                 }
  121.                         break;
  122.                 case 'p':               /* P = Put command */
  123.                         if((_n=mlreply("Remote filename: ",getfiln,NFILEN))!=TRU
  124. E)
  125.                                 return(_n);
  126.                 case 's':               /* S = Send command */
  127.                         if(usebuffer(NULL,NULL) != TRUE)
  128.                                 return(FALSE);
  129.                         if (key == 's')
  130.                                 strcpy(getfiln,curbp->b_bname);
  131.                         gotobob(NULL, 1);
  132.                         update();
  133.                         if((_n=sendsw()) == FALSE)
  134.                                 {
  135.                                 if (key == 's')
  136.                                         mlwrite("Send failed");
  137.                                 else
  138.                                         mlwrite("Put failed");
  139.                                 (*term.t_beep)();
  140.                                 }
  141.                         if (key == 's')
  142.                                 connect();
  143.                         break;
  144.                 case 't':              /* T = transmit command */
  145.                         if(usebuffer(NULL,NULL) != TRUE)
  146.                                 return(FALSE);
  147.                         gotobob(NULL, 1);
  148.                         update();
  149.                         mlwrite("[Transmitting: %s]",curbp->b_bname);
  150.                         trans();
  151.                         connect();
  152.                         break;
  153.                 default:
  154.                         mlwrite("Connect, Send, Receive, Get, Put, Finish, Bye\
  155. , Log, Transfer");
  156.  
  157.                         return(FALSE);
  158.                 }
  159.         /* Restore controlling tty's modes */
  160.  
  161.         owf |= WFHARD; owf |= WFMODE;
  162.         curwp->w_flag |= owf;
  163.         sgarbf = TRUE;  /* we know screen is garbage after connect */
  164.         update();
  165.         return(TRUE);
  166. }
  167.  
  168. /*
  169. *      c o n n e c t
  170. *
  171. * Establish a virtual terminal connection with the remote host, over an
  172. * assigned tty line.
  173. */
  174.  
  175. connect()
  176. {
  177.         register int c;
  178.  
  179.         setterm(REMOTE);
  180.         while (1)
  181.                 {
  182.                 if (Bconstat(2))
  183.                         if(readcon() == FALSE)
  184.                                 break;
  185.                 if (Bconstat(1))
  186.                         {
  187.                         c=readaux();
  188.                         ttputc(c);
  189.                         if (logfile)
  190.                                 {
  191.                                 if (c=='\n')
  192.                                         {
  193.                                         lnewline();
  194.                                         continue;
  195.                                         }
  196.                                 if (c=='\r')
  197.                                         continue;
  198.                                 linsert(1,c);
  199.                                 }
  200.                         }
  201.                 }
  202.         setterm(HOST);
  203.         return(FALSE);
  204. }
  205.  
  206. /* set up terminal's screen and allow it to be saved for later.
  207.  */
  208. setterm(f)
  209. int f;
  210. {
  211.         static char scrbase[0x7d10];
  212.         static unsigned char firsttime =